package com.microinvest.controller.user;
import com.microinvest.entity.BuyStock;
import com.microinvest.entity.SellStock;
import com.microinvest.entity.UserStockFavorites;
import com.microinvest.service.BusinessService;
import com.microinvest.service.UserGetService;
import com.microinvest.util.Result;
import com.microinvest.util.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/userStock")
public class UserStockController {

    private final BusinessService businessService;

    private final UserGetService userGetService;

    @Autowired
    public UserStockController(BusinessService businessService,UserGetService userGetService){
        this.businessService=businessService;
        this.userGetService=userGetService;
    }

    //用户收藏股票
    @PostMapping("/starStock")
    public Result<String> userStarStock(String stockSymbol){
        Map<String,Integer> map = ThreadLocalUtil.get();
        int userId=map.get("userId");
        Result result=businessService.userStarStock(userId,stockSymbol);
        return result;
    }

    //用户查看收藏股票信息
    @GetMapping("/getStarStock")
    public Result<List<UserStockFavorites>> getUserStarStock(){
        Result result=userGetService.getUserStockFavorites();
        return result;
    }

    //用户查看自己购买股票信息
    @GetMapping("/getBuyStock")
    public Result<List<BuyStock>> getUserBuyStock(){
        Result result=userGetService.getUserBuyStock();
        return result;
    }

    //用户查看自己卖出股票信息
    @GetMapping("/getSellStock")
    public Result<List<SellStock>> getUserSellStock(){
        Result result=userGetService.getUserSellStock();
        return result;
    }


}
